package com.xiaotu.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @author 张晓
 * @create 2020-06-25 19:29
 */
public class OutPutImpl {
    List<Colleage> colleageList;

    public OutPutImpl(List<Colleage> colleageList) {
        this.colleageList = colleageList;
    }

    //遍历所有学院，然后调用printDepartment
    public void printColleage(){
        //从colleageList 取出所有的学院 java中的list 已经实现了iterator
        Iterator<Colleage> iterator = colleageList.iterator();
        while (iterator.hasNext()){
            //取出一个学院
            Colleage colleage = iterator.next();
            System.out.println("======="+ colleage.getName() +"=======");
            //得到对应的迭代器
            printDepartment(colleage.createIterator());
        }
    }

    //输出学院  输出系
    public void printDepartment(Iterator iterator){
        while (iterator.hasNext()){
            Department d = (Department) iterator.next();
            System.out.println(d.getName());
        }
    }

}
